package com.medistat.security;

import java.security.MessageDigest;

import org.bouncycastle.util.encoders.Base64;



public abstract class Decoder {

	//Use getMD5_Base64 method below instead of decode.
	@Deprecated
	public static String decode(String username, String password) {
		return String.valueOf(username.hashCode() ^ password.hashCode());
	}
	
	public static synchronized String getMD5_Base64(String input) {

		MessageDigest digest=null;
        try {
            digest = MessageDigest.getInstance("MD5");
        } catch (Exception ex) {
        }

        if (digest == null) {
            return input;
        }
        try {
            digest.update(input.getBytes("UTF-8"));
        } catch (java.io.UnsupportedEncodingException ex) {
        }
        byte[] rawData = digest.digest();
        byte[] encoded = Base64.encode(rawData);
        String retValue = new String(encoded);
        return retValue;
    }
}
